﻿using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Gezel.Model.Errors;

namespace Weazel.Gezel.Model
{
	public static class Identifier
	{
		/// <summary>
		/// List of vhdl keywords
		/// </summary>
		static readonly string[] VhdlKeywords = 
			{
				"abs",
				"access",
				"after",
				"alias",
				"all",
				"and",
				"architecture",
				"array",
				"assert",
				"attribute",
				"begin",
				"block",
				"body",
				"buffer",
				"bus",
				"case",
				"component",
				"configuration",
				"constant",
				"disconnect",
				"downto",
				"else",
				"elsif",
				"end",
				"entity",
				"exit",
				"file",
				"for",
				"function",
				"generate",
				"generic",
				"group",
				"guarded",
				"if",
				"impure",
				"in",
				"inertial",
				"inout",
				"is",
				"label",
				"library",
				"linkage",
				"literal",
				"loop",
				"map",
				"mod",
				"nand",
				"new",
				"next",
				"nor",
				"null",		
				"of",
				"on",
				"open",
				"or",
				"others",
				"out",
				"package",
				"port",
				"postponed",
				"procedure",
				"process",
				"pure",
				"range",
				"record",
				"register",
				"reject",
				"rem",
				"report",
				"return",
				"rol",
				"ror",
				"select",
				"severity",
				"signal",
				"sla",
				"sll",
				"sra",
				"srl",
				"subtype",
				"then",
				"to",
				"transport",
				"type",
				"unaffected",
				"units",
				"until",
				"use",
				"variable",
				"wait",
				"when",
				"while",
				"with",
				"xnor",
				"xor",
				"command" // not a vhdl keyword but used by the badger tool 
			};


		public static void Verify(ref List<VerificationError> errors, ref List<VerificationWarning> warnings, string identifier, Position position)
		{
			// check for vhdl keywords
			foreach(string keyword in VhdlKeywords)
				if (identifier == keyword)
				{
					ErrorMessage message = new ErrorMessage();
					message.AddString(String.Format("Identifier '{0}' at ", identifier));
					message.AddPosition(position);
					message.AddString(" is a VHDL keyword. If you plan to convert this design to VHDL the resulting design may not compile.");

					warnings.Add(new VerificationWarning(message));
				}

			// double underscore may also cause problems
			if (identifier.Contains("__"))
			{
				ErrorMessage message = new ErrorMessage();
				message.AddString(String.Format("Identifier '{0}' at ", identifier));
				message.AddPosition(position);
				message.AddString(" contains adjacent underscores. If you plan to convert this design to VHDL the resulting design may not compile.");

				warnings.Add(new VerificationWarning(message));
			}
		}
	}
}
